home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / sdidialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-12  |  18.1 KB  |  821 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11. // SdiDialog.cpp : implementation file
  12. //
  13.  
  14.  
  15. #include "stdafx.h"
  16. #include "InsSmObj.h"
  17. #include "SdiDialog.h"
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. //const    HRESULT hRes = S_OK;
  26.  
  27. const IID LIBID_IMSIGXLib = {0x6A481400,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  28. const IID IID_PickResult = {0x6A481123,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  29. const IID IID_Graphics = {0x6A48110A, 0xE531, 0x11CF, {0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  30. const IID IID_View = {0x6A481110, 0xE531, 0x11CF, {0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  31. const IID IID_Window = {0x6A481124, 0xE531, 0x11CF, {0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF} };
  32. const CLSID CLSID_Application  = {0x6A481001,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  33. const CLSID CLSID_XGraphic  = {0x6A481803,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  34.  
  35.  
  36. static const IID IID_IAppEvents = { 0x6A481301, 0xE531, 0x11CF, { 0xA1, 0x15, 0x0, 0xA0, 0x24, 0x15, 0x8D, 0xAF } };
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CSdiDialog dialog
  40.  
  41.     long a = 0;
  42.  
  43. BEGIN_MESSAGE_MAP(CSdiDialog, CDialog)
  44.     //{{AFX_MSG_MAP(CSdiDialog)
  45.     ON_BN_CLICKED(ID_CLOSE, OnClose)
  46.     ON_WM_SYSCOMMAND()
  47.     ON_WM_DESTROY()
  48.     ON_BN_CLICKED(ID_INSERTSYMB, OnInsertsymb)
  49.     //}}AFX_MSG_MAP
  50. ///    ON_LBN_DBLCLK(IDC_LIST1, onDoubleClick)
  51. END_MESSAGE_MAP()
  52.  
  53.  
  54. BEGIN_DISPATCH_MAP(CSdiDialog, CDialog)
  55.     //{{AFX_DISPATCH_MAP(CTCEventsApp)
  56.     DISP_FUNCTION(CSdiDialog, "MouseDown", MouseDown, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_I2 VTS_I4 VTS_I4 VTS_I4 VTS_PBOOL)
  57.     DISP_FUNCTION(CSdiDialog, "MouseUp", MouseUp, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_I2 VTS_I4 VTS_I4 VTS_I4 VTS_PBOOL)
  58.     DISP_FUNCTION(CSdiDialog, "MouseMove", MouseMove, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_I4 VTS_I4 VTS_I4 VTS_PBOOL)
  59.     DISP_FUNCTION(CSdiDialog,    "DrawingBeforeClose", DrawingBeforeClose, VT_EMPTY, VTS_DISPATCH VTS_PBOOL)
  60.     //}}AFX_DISPATCH_MAP
  61. END_DISPATCH_MAP()
  62.  
  63.  
  64. BEGIN_INTERFACE_MAP(CSdiDialog, CDialog)
  65.     INTERFACE_PART(CSdiDialog, IID_IAppEvents, Dispatch)
  66. END_INTERFACE_MAP()
  67.  
  68.  
  69. void CSdiDialog::MouseDown(LPDISPATCH WhichDrawing, LPDISPATCH WhichView, LPDISPATCH WhichWindow, short Button, long Shift, long X, long Y, IMSI_BOOL* pbCancel)
  70. {
  71. // Do nothing on this event
  72.     *pbCancel = FALSE;
  73.  
  74. }
  75.  
  76. void CSdiDialog::MouseUp(LPDISPATCH WhichDrawing, LPDISPATCH WhichView, LPDISPATCH WhichWindow, short Button, long Shift, long X, long Y, IMSI_BOOL* pbCancel)
  77. {
  78.  
  79.     
  80.     COleVariant varItem = (0L);
  81.     COleVariant varOptional(varMissing);
  82.  
  83.     IDrawing *pIDwgTrg = NULL; /// current drawing
  84.     pIDwgTrg = (IDrawing*) WhichDrawing;
  85.     pIDwgTrg->AddRef();
  86.  
  87.     Graphics *pGrs = NULL;
  88.  
  89.     *pbCancel = FALSE;
  90.  
  91.     CPoint point;
  92.     point.x = X;
  93.     point.y = Y;
  94.  
  95.     
  96.     try 
  97.     {
  98.         if(m_pDragGraphic != 0)
  99.         {
  100.  
  101.             hRes = pIDwgTrg->get_Graphics(&pGrs); // get current drawing's graphics collection
  102.             CHECK_HRESULT(hRes)
  103.  
  104.             CPreviewWnd *pPreview = (CPreviewWnd *) (GetDlgItem(IDC_PREVIEW));
  105.  
  106.             hRes = pGrs->AddGraphic(m_pDragGraphic, varOptional, varOptional);
  107.             CHECK_HRESULT(hRes)
  108.  
  109.             hRes = m_pDragGraphic->Update();
  110.             CHECK_HRESULT(hRes)
  111.  
  112.             if(m_pTCADView != NULL)
  113.             {
  114.                 m_pTCADView->Release();
  115.                 m_pTCADView = NULL;
  116.             }
  117.                 
  118.             m_pTCADView = (View*) WhichView;
  119.             m_pTCADView->AddRef();
  120.  
  121. // End drag of external object
  122.             EndDrag(point);
  123.  
  124.             hRes = m_pTCADView->Refresh();
  125.             CHECK_HRESULT(hRes)
  126.  
  127.             m_DraggingMode = FALSE;    
  128.         }    
  129.     }        
  130.     catch (...)
  131.     {
  132.         TRACE_EXCEPTION("CSdiDialog::MouseUp")
  133.     }
  134.     
  135.     if(m_pDragGraphic != NULL)
  136.     {
  137.         m_pDragGraphic->Release();
  138.         m_pDragGraphic = NULL;
  139.     }
  140.     if (m_pTCADView != NULL)
  141.     {
  142.         m_pTCADView->Release();
  143.         m_pTCADView = NULL;
  144.     }
  145.  
  146.     if (pGrs != NULL)
  147.     {
  148.         pGrs->Release();
  149.         pGrs = NULL;
  150.     }
  151.  
  152.     if(pIDwgTrg != NULL) 
  153.     {
  154.         pIDwgTrg->Release();
  155.         pIDwgTrg = NULL;
  156.     }
  157. }
  158.  
  159. void CSdiDialog::MouseMove(LPDISPATCH WhichDrawing, LPDISPATCH WhichView, LPDISPATCH WhichWindow, long Shift, long X, long Y, IMSI_BOOL* pbCancel)
  160. {
  161.     CPoint point;
  162.     point.x = X;
  163.     point.y = Y;
  164.  
  165.     *pbCancel = FALSE;
  166.     
  167.     View *pTCADCurrentView = NULL;
  168.     COleVariant varItem = (1L);
  169.     
  170.     try 
  171.     {
  172.  
  173.         if (m_DraggingMode == TRUE) 
  174. // Run BeginDrag function on first MouseMove after user start drag ExternalObject
  175.         {
  176.     
  177.             HCURSOR hOC = ::SetCursor(::LoadCursor(NULL,IDC_WAIT));
  178.  
  179.             if(m_pTCADView != NULL)
  180.             {
  181.                 RELEASE(m_pTCADView);
  182.             }
  183.  
  184.             m_pTCADView = (View *)WhichView;
  185.             m_pTCADView->AddRef();
  186.  
  187.             CPreviewWnd *pPreview = (CPreviewWnd *) (GetDlgItem(IDC_PREVIEW));
  188.  
  189.             hRes = pPreview->m_pPreviewGraphic->Duplicate(&m_pDragGraphic);
  190.             CHECK_HRESULT(hRes)
  191.             m_pDragGraphic->Release();
  192.             m_pDragGraphic = NULL;
  193.                 
  194.             hRes = pPreview->m_pPreviewGrs->Remove(&varItem, &m_pDragGraphic);
  195.             CHECK_HRESULT(hRes)
  196.             
  197.             hRes = m_pDragGraphic->put_ID(0);
  198.             CHECK_HRESULT(hRes)
  199.  
  200.             m_DraggingMode = FALSE;
  201.             ::SetCursor(hOC);
  202.  
  203.             BeginDrag(point);
  204.         }
  205.         else 
  206.         {
  207.             if (m_pDragGraphic != NULL && !m_bDragging)
  208.             {
  209.                 if (!BeginDrag(point))
  210.                 {
  211.                     m_pDragGraphic->Release();
  212.                     m_pDragGraphic = NULL;
  213.                 }
  214.             }
  215.             else if (m_bDragging)
  216.             {
  217.                 pTCADCurrentView = (View *)WhichView;
  218.                 pTCADCurrentView->AddRef();
  219. //It is possible in TurboCAD to have several views opened in the same time
  220. //(ISOMETRIC and PLAN for example) so we have to free pointer for m_pTCADView and get it again
  221.                 if (pTCADCurrentView != m_pTCADView) // if view is changed (user drag external object over another view) then restart drag
  222.                 {
  223.                     if(m_pTCADView != NULL)
  224.                     {
  225.                         RELEASE(m_pTCADView);
  226.                     }
  227.  
  228.                     m_pTCADView = (View *)WhichView;
  229.                     m_pTCADView->AddRef();
  230.                     pTCADCurrentView->Release();
  231.                     pTCADCurrentView = NULL;
  232.  
  233.                     RestartDrag(point);                
  234.                 }
  235.                 Drag(point);
  236.             }    
  237.             
  238.         }
  239.     }    
  240.     catch (...)
  241.     {
  242.         TRACE_EXCEPTION("CSdiDialog::OnMouseMove")
  243.     }
  244. }
  245.  
  246.  
  247.  
  248. void CSdiDialog::DisconnectEvents()
  249. {
  250.     if (m_pIApplication == NULL || m_dwEventConnection == 0)
  251.         return;
  252.     try 
  253.     {
  254.         HRESULT    hRes = m_pIApplication->DisconnectEvents(m_dwEventConnection);
  255.         CHECK_HRESULT(hRes)
  256.         if (FAILED(hRes))
  257.         {
  258.             AfxMessageBox(IDS_DISCONNECTFAILED);
  259.             return;
  260.         }
  261.         m_dwEventConnection = 0;
  262.     }
  263.     catch (...)
  264.     {
  265.         TRACE_EXCEPTION("CSdiDialog::DisconnectEvents")
  266.     }
  267.  
  268.     if(m_pIApplication != NULL)
  269.     {
  270.         m_pIApplication->Release(); 
  271.         m_pIApplication = NULL;
  272.     }
  273. }
  274.  
  275.  
  276. CSdiDialog::CSdiDialog(CInsSmObj* pTool, CWnd* pParent, /*=NULL*/RegenMethods *pRgs)
  277.     : CDialog(CSdiDialog::IDD, pParent),
  278.     m_dwEventConnection(0),
  279. //    m_dwEventMask(~0UL),
  280.     m_pIApplication(NULL),
  281.     m_ptMouseDown(CPoint(0, 0)),
  282.     m_DraggingMode(FALSE),
  283.     m_bDragging(FALSE),
  284.     m_pTCADView(NULL),
  285.     m_pDragGraphic(NULL)
  286.  
  287. {
  288.  
  289.     //{{AFX_DATA_INIT(CSdiDialog)
  290.     m_listbox = _T("");
  291.     //}}AFX_DATA_INIT
  292.     m_dwEventMask = imsiEventMouseUp
  293. //                             | imsiEventSelectionChange
  294.                              | imsiEventMouseDown
  295.                              | imsiEventMouseMove
  296.                              | imsiEventMouseDown
  297.                              | imsiEventDrawingBeforeClose;
  298.         
  299.     m_pTool = pTool;
  300.     m_pTool->AddRef();
  301.     m_pTool->m_bRunned = TRUE;
  302.     m_pRegMets = pRgs;
  303.     ADDREF(m_pRegMets);
  304. }
  305.  
  306.  
  307. void CSdiDialog::DoDataExchange(CDataExchange* pDX)
  308. {
  309.     CDialog::DoDataExchange(pDX);
  310.     //{{AFX_DATA_MAP(CSdiDialog)
  311.     DDX_LBString(pDX, IDC_EXTOBJECTSLIST, m_listbox);
  312.     //}}AFX_DATA_MAP
  313. }
  314.  
  315.  
  316. /////////////////////////////////////////////////////////////////////////////
  317. // CSdiDialog message handlers
  318.  
  319. BOOL CSdiDialog::OnInitDialog() 
  320. {
  321.     CDialog::OnInitDialog();
  322.     
  323.     m_list.SubclassDlgItem( IDC_EXTOBJECTSLIST , this );
  324.     CExternalObjectsList *pList = (CExternalObjectsList *)GetDlgItem(IDC_EXTOBJECTSLIST);
  325.  
  326.     m_wndView.SubclassDlgItem(IDC_PREVIEW, this);
  327.     CPreviewWnd *pView = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  328.  
  329.     COleVariant varItem;
  330.     CString cstrDesc;
  331.     CString cstrName;
  332.  
  333.     HRESULT hRes = S_OK;
  334.     RegenMethod *pRegMet = NULL;
  335.     BSTR bstrDescription = NULL;
  336.     BSTR bstrName = NULL;
  337.     ImsiRegenMethodType regenType;
  338.     EnableAutomation();
  339.  
  340.     long NumRegs = 0;
  341.     
  342.     try
  343.     {
  344.         hRes = m_pRegMets->get_Count(&NumRegs);
  345.         CHECK_HRESULT(hRes)
  346. //        fill the ExternalObject list with list of external objects 
  347.         for(long i = 0;i < NumRegs; i++)
  348.         {
  349.             varItem = i;
  350.  
  351. // Retreive collection of External objects (Regen Methods - in TurboCAD's terminology)
  352.             hRes = m_pRegMets->get_Item(&varItem,&pRegMet);
  353.             CHECK_HRESULT(hRes)
  354.  
  355.             hRes = pRegMet->get_Type(®enType);
  356.             CHECK_HRESULT(hRes)
  357.  
  358. // Check if the External object is created with SDK and support automation.
  359.             if(regenType == imsiAutomation)
  360.             {
  361.                 hRes = pRegMet->get_Description(&bstrDescription);
  362.                 if (SUCCEEDED(hRes))
  363.                 {
  364.                     cstrDesc = bstrDescription;
  365.                     ::SysFreeString(bstrDescription);
  366.                     bstrDescription = NULL;        
  367.                 
  368.                     hRes = pRegMet->get_Name(&bstrName);
  369.                     CHECK_HRESULT(hRes)
  370.                 
  371.                     cstrName = bstrName;
  372.                     ::SysFreeString(bstrName);
  373.                     bstrName = NULL;        
  374. // cut some external objects from the list because they are auxiliary objects.
  375.                     if(cstrName == "Foundation.House" || cstrName == "AutoDim.House" || cstrName == "Schedule.Block" || cstrName == "Fillet3D_Regen.Fillet3D")
  376.                     {
  377.                         //Do nothing 
  378.                     }
  379.                     else
  380.                     {
  381.                         pList->AddString(cstrName);
  382.                     }
  383.                 }
  384.             }
  385.  
  386.         }
  387.         if(pList->SetCurSel(0) != LB_ERR)
  388.         {
  389.             pList->GetText(0 ,(pList->m_cstrCurSelected));
  390.  
  391.             pView->CreatePreview();
  392.             pView->DoPreview();            
  393.  
  394.             
  395. // Connect to TurboCAD's events            
  396.             ConnectEvents();
  397.         }
  398.  
  399.     }
  400.     catch (...)
  401.     {
  402.         TRACE_EXCEPTION("CSdiDialog::OnInitDialog")
  403.     }
  404.  
  405.     if (pRegMet != NULL)
  406.     {
  407.         pRegMet->Release();
  408.         pRegMet = NULL;
  409.     }
  410.  
  411.     if (bstrDescription != NULL)
  412.         ::SysFreeString(bstrDescription);
  413.  
  414.     if (bstrName != NULL)
  415.         ::SysFreeString(bstrName);
  416.  
  417.     return TRUE;  // return TRUE unless you set the focus to a control
  418.                   // EXCEPTION: OCX Property Pages should return FALSE
  419. }
  420.  
  421. void CSdiDialog::PostNcDestroy() 
  422. {
  423.     CDialog::PostNcDestroy();
  424.     RELEASE(m_pRegMets)
  425.     delete this;
  426. }
  427.  
  428. void CSdiDialog::OnClose() 
  429. {
  430.     // TODO: Add your message handler code here and/or call default
  431.  
  432.     if(m_dwEventConnection != 0) // Disconnect from TurboCAD's events if connection is established.
  433.     {
  434.         DisconnectEvents();
  435.     }
  436.     
  437.     m_pTool->m_bRunned = FALSE;
  438.     if(m_pTool != NULL)
  439.     {
  440.         m_pTool->Release ();
  441.         m_pTool = NULL;
  442.     }
  443.  
  444.     if(m_pRegMets != NULL)
  445.     {
  446.         m_pRegMets->Release();
  447.         m_pRegMets = NULL;
  448.     }
  449.  
  450.     CPreviewWnd *pView = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  451.     pView->ClearAll();
  452.  
  453.     CDialog::OnClose();
  454.     DestroyWindow();
  455. }
  456.  
  457.  
  458.  
  459. void CSdiDialog::ConnectEvents()
  460. {
  461.     HRESULT hRes = S_OK;
  462.  
  463.     if (m_dwEventConnection != 0)
  464.     {
  465.         AfxMessageBox(IDS_ALREADYCONNECTED);
  466.         return;
  467.     }
  468.     
  469.     m_pIApplication = NULL;
  470.     try
  471.     {
  472.         hRes = m_pRegMets->get_Application(&m_pIApplication);
  473.         CHECK_HRESULT(hRes)
  474.  
  475.         if (m_pIApplication == NULL)
  476.         {
  477.                 AfxMessageBox(IDS_CANTGETTCAPP);
  478.                 return;
  479.         }
  480.  
  481.         IDispatch* pUnkEventSink = GetIDispatch(TRUE);
  482.  
  483.         UpdateData(TRUE);
  484.         COleVariant var((long)m_dwEventMask);
  485.         hRes = m_pIApplication->ConnectEvents(pUnkEventSink,
  486.             &var,
  487.             (long*)&m_dwEventConnection);
  488.         
  489.         CHECK_HRESULT(hRes)
  490.         if (FAILED(hRes))
  491.         {
  492.             AfxMessageBox(IDS_CONNECTIONNOTESTABLISHED);
  493.             return;
  494.         }
  495.     }
  496.     catch (...)
  497.     {
  498.         TRACE_EXCEPTION("CSdiDialog::ConnectEvents")
  499.     }
  500. }
  501.  
  502.  
  503.  
  504. void CSdiDialog::OnSysCommand(UINT nID, LPARAM lParam )
  505. {
  506.     if (nID == SC_CLOSE)
  507.     {
  508.         if(m_dwEventConnection != 0)
  509.         DisconnectEvents();
  510.     
  511.         m_pTool->m_bRunned = FALSE;
  512.         if(m_pTool != NULL)
  513.         {
  514.             m_pTool->Release ();
  515.             m_pTool = NULL;
  516.         }
  517.  
  518.         if(m_pRegMets != NULL)
  519.         {
  520.             m_pRegMets->Release();
  521.             m_pRegMets = NULL;
  522.         }
  523.         
  524.         CPreviewWnd *pPreview = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  525.         pPreview->ClearAll();
  526.     }
  527.     CDialog::OnSysCommand(nID, lParam );
  528.  
  529. }
  530.  
  531. ///------------------------------------------
  532. // DragOutline functions
  533. BOOL CSdiDialog::BeginDrag(const CPoint& point)
  534. {
  535.     VariantClear(&m_dragOutline);
  536.     SAFEARRAYBOUND bound;
  537.     bound.cElements = 0;
  538.     bound.lLbound = 0;
  539.     m_dragOutline.vt = VT_ARRAY|VT_R8;
  540.     m_dragOutline.parray = ::SafeArrayCreate(VT_R8, 1, &bound);
  541.  
  542.     BoundingBox* Box = NULL;
  543.     IVertex* vMax = NULL;
  544.     IVertex* vMin = NULL;
  545.     double x, y, x1, y1;
  546.     x = x1 = y = y1 = 0;
  547.     try
  548.     {
  549.         HRESULT hRes = m_pDragGraphic->CreateDragOutline(&m_dragOutline);
  550.         CHECK_HRESULT(hRes)
  551.  
  552.         m_bDragging = TRUE;
  553.         m_pDragGraphic->put_Visible(FALSE);
  554.         VARIANT varState;
  555.         varState.vt = VT_I4;
  556.         varState.lVal = imsiDragBegin;
  557.  
  558.         hRes = m_pDragGraphic->CalcBoundingBox(NULL, &Box);
  559.         CHECK_HRESULT(hRes)
  560.  
  561.         hRes = Box->get_Max(&vMax);
  562.         CHECK_HRESULT(hRes)
  563.  
  564.         hRes = Box->get_Min(&vMin);
  565.         CHECK_HRESULT(hRes)
  566.  
  567.         hRes = vMax->get_X(&x);
  568.         CHECK_HRESULT(hRes)
  569.  
  570.         hRes = vMax->get_Y(&y);
  571.         CHECK_HRESULT(hRes)
  572.  
  573.         hRes = vMin->get_X(&x1);
  574.         CHECK_HRESULT(hRes)
  575.  
  576.         hRes = vMin->get_Y(&y1);
  577.         CHECK_HRESULT(hRes)
  578.  
  579.         x = x1 + (x - x1)/2;
  580.         y = y1 + (y - y1)/2;
  581.         hRes = m_pTCADView->ViewToScreen(x, y, &x1, &y1, NULL);
  582.         CHECK_HRESULT(hRes)
  583.  
  584.         hRes = m_pTCADView->DragOutline(&m_dragOutline, x1, y1, &varState);
  585.         CHECK_HRESULT(hRes)
  586.         
  587.  
  588.         varState.lVal = imsiDragContinue;
  589.         hRes = m_pTCADView->DragOutline(&m_dragOutline, point.x, point.y, &varState);
  590.         CHECK_HRESULT(hRes)
  591.     }
  592.     catch (...)
  593.     {
  594.         TRACE_EXCEPTION("CSdiDialog::BeginDrag")
  595.     }
  596.     if (vMin != NULL)
  597.     {
  598.         vMin->Release();
  599.         vMin = NULL;
  600.     }
  601.     if (vMax != NULL)
  602.     {
  603.         vMax->Release();
  604.         vMax = NULL;
  605.     }
  606.     if (Box != NULL)
  607.     {
  608.         Box->Release();
  609.         Box = NULL;
  610.     }
  611.  
  612.     return TRUE;
  613. }
  614.  
  615. void CSdiDialog::Drag(const CPoint& point)
  616. {
  617.     if (m_pTCADView == NULL)
  618.         return;
  619.  
  620.     VARIANT varState;
  621.     varState.vt = VT_I4;
  622.     varState.lVal = imsiDragContinue;
  623.  
  624.     try
  625.     {
  626.         HRESULT hRes = m_pTCADView->DragOutline(&m_dragOutline, point.x, point.y, &varState);
  627.         CHECK_HRESULT(hRes)
  628.     }
  629.     catch (...)
  630.     {
  631.         TRACE_EXCEPTION("CSdiDialog::Drag")
  632.     }
  633.     
  634. }
  635.  
  636. void CSdiDialog::EndDrag(const CPoint& point)
  637. {
  638.     m_bDragging = FALSE;
  639.     if (m_pTCADView == NULL || m_pDragGraphic == NULL)
  640.         return;
  641.  
  642.     VARIANT varState;
  643.     varState.vt = VT_I4;
  644.     varState.lVal = imsiDragEnd;
  645.     IMatrix *pMat = NULL;
  646.  
  647.     try 
  648.     {
  649.         HRESULT hRes = m_pTCADView->DragOutline(&m_dragOutline, point.x, point.y, &varState);
  650.         CHECK_HRESULT(hRes)
  651.  
  652.         VariantClear(&m_dragOutline);
  653.  
  654.         double dx, dy, dz;
  655.         dx = dy = dz = 0;
  656.  
  657.         double dxWorld, dyWorld, dzWorld;
  658.         dxWorld = dyWorld = dzWorld = 0;
  659.         hRes = m_pTCADView->ScreenToView(point.x, point.y, &dx, &dy);
  660.         CHECK_HRESULT(hRes)
  661.  
  662.         VARIANT var;
  663.         var.vt = VT_ERROR;
  664.         var.scode = DISP_E_PARAMNOTFOUND;
  665.  
  666.         ImsiSpaceModeType curMode;    
  667.  
  668.         hRes = m_pTCADView->get_SpaceMode(&curMode);
  669.         CHECK_HRESULT(hRes)
  670.         dxWorld = dx;
  671.         dyWorld = dy; 
  672.  
  673.         if(curMode == imsiModelSpace)
  674.         {
  675.             hRes = m_pTCADView->ViewToWorld(dx, dy, dz, &dxWorld, &dyWorld, &dzWorld);
  676.             CHECK_HRESULT(hRes)
  677.         }
  678.         hRes = m_pDragGraphic->MoveAbsolute(dxWorld, dyWorld, 0, &var, &var, &var, &pMat);
  679.         CHECK_HRESULT(hRes)
  680.         m_pDragGraphic->put_Visible(TRUE);
  681.     }
  682.     catch (...)
  683.     {
  684.         TRACE_EXCEPTION("CSdiDialog::EndDrag")
  685.     }
  686.  
  687.     if(pMat != NULL)
  688.     {
  689.         pMat->Release();
  690.         pMat = NULL;
  691.     }
  692.     if (m_pDragGraphic != NULL)
  693.     {
  694.         m_pDragGraphic->Release();
  695.         m_pDragGraphic = NULL;
  696.     }
  697. }
  698.  
  699. void CSdiDialog::RestartDrag(const CPoint& point)
  700. {
  701.     try
  702.     {
  703.         m_bDragging = FALSE;
  704.         VARIANT varState;
  705.         varState.vt = VT_I4;
  706.         varState.lVal = imsiDragEnd;
  707.         HRESULT hRes = m_pTCADView->DragOutline(&m_dragOutline, point.x, point.y, &varState);
  708.         CHECK_HRESULT(hRes)
  709.  
  710.         VariantClear(&m_dragOutline);
  711.         BeginDrag(point);
  712.     }
  713.     catch (...)
  714.     {
  715.         TRACE_EXCEPTION("CSdiDialog::RestartDrag")
  716.     }
  717. }
  718.  
  719. void CSdiDialog::DrawingBeforeClose(LPDISPATCH WhichDrawing, BOOL FAR* Cancel)
  720. {
  721.     *Cancel = FALSE;
  722.     Drawings *pDrs = NULL;
  723.     long n = 0;
  724.  
  725.     try
  726.     {
  727.         HRESULT hRes = m_pIApplication->get_Drawings(&pDrs);
  728.         CHECK_HRESULT(hRes)
  729.         hRes = pDrs->get_Count(&n);
  730.         CHECK_HRESULT(hRes)
  731.  
  732.         if (n == 2)
  733.         {
  734.  
  735.         if(m_dwEventConnection != 0)
  736.             DisconnectEvents();
  737.             m_pTool->m_bRunned = FALSE;
  738.  
  739.             CPreviewWnd *pView = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  740.             pView->ClearAll();
  741.             CSdiDialog::OnClose();
  742.         }
  743.  
  744.     }
  745.     catch (...)
  746.     {
  747.  
  748.         TRACE_EXCEPTION("CSdiDialog::DrawingBeforeClose")
  749.     }
  750.  
  751.     if (pDrs != NULL)
  752.     {
  753.         pDrs->Release();
  754.         pDrs = NULL;
  755.     }
  756. }
  757.  
  758. void CSdiDialog::OnInsertsymb() 
  759. {
  760.     HRESULT hRes = E_FAIL;
  761.     IGraphic *pIGr = NULL;
  762.     IDrawing *pActDr = NULL;
  763.     Graphics *pGrs = NULL;
  764.     COleVariant varItem = (1L);
  765.     COleVariant varOptional(varMissing);
  766.     View *pView = NULL;
  767.     try
  768.     {
  769.             CPreviewWnd *pPreview = (CPreviewWnd *) (GetDlgItem(IDC_PREVIEW));
  770.             if (m_pIApplication)
  771.             {
  772.                 hRes = m_pIApplication->get_ActiveDrawing(&pActDr);
  773.                 if (SUCCEEDED(hRes) && pActDr)
  774.                 {
  775.  
  776.                     hRes = pActDr->get_Graphics(&pGrs);
  777.                     if (SUCCEEDED(hRes) && pGrs)
  778.                     {
  779.  
  780.                         if (pPreview->m_pPreviewGraphic)
  781.                         {
  782.                             hRes = pPreview->m_pPreviewGraphic->Duplicate(&pIGr);
  783.                             CHECK_HRESULT(hRes)
  784.                                 
  785.                             RELEASE(pIGr);
  786.  
  787.                             hRes = pPreview->m_pPreviewGrs->Remove(&varItem, &pIGr);
  788.                             CHECK_HRESULT(hRes)
  789.                             
  790.                             hRes = pIGr->put_ID(0);
  791. //                            CHECK_HRESULT(hRes)
  792.                             hRes = pGrs->AddGraphic(pIGr, varOptional, varOptional);
  793.                             CHECK_HRESULT(hRes)
  794.  
  795.                             hRes = pIGr->Update();
  796.                             //CHECK_HRESULT(hRes)
  797.                             RELEASE(pIGr);
  798.                             
  799.                             hRes = pActDr->get_ActiveView(&pView);
  800.                             if (SUCCEEDED(hRes) && pView)
  801.                             {
  802.                                 hRes = pView->Refresh();
  803.                                 RELEASE(pView)
  804.                             }
  805.                         }
  806.                         RELEASE(pGrs)
  807.                     }
  808.                     RELEASE(pActDr)
  809.                 }        
  810.             }
  811.  
  812.     }
  813.     catch(...)
  814.     {
  815.         TRACE("void CSdiDialog::OnInsertsymb() ");
  816.     }
  817.  
  818.  
  819.  
  820. }
  821.